import { Stage, Scene, PerspectiveCamera, Vector3 } from 'tinoe'
import { ParticlePlugin, Texture2DLoader } from '@tinoe/glk'
// import * as dat from 'dat.gui'
import leafMap from '../images/l1.png'

const canvas = document.getElementById('background')
const stage = new Stage({ canvas })
const scene = new Scene()
const camera = new PerspectiveCamera({
    position: [0, 0, 50]
})

scene.cameraManager.addCameras(camera)

stage.loop(() => {
    stage.run(scene)
})

const particleSystem = scene.addPlugin(ParticlePlugin)

const leafTexture = await Texture2DLoader.load(leafMap)
const leaves = particleSystem.add('leaf')

leaves.maxCount = 100;
leaves.life = 30;
leaves.size = 1;
leaves.sizeFactor = 2;
leaves.startTimeFactor = 10;
leaves.position = new Vector3(20, 20, 20);
leaves.positionFactor = new Vector3(10, 10, 10);
leaves.rotateSpeed = 0.5;
leaves.rotateSpeedFactor = 1;
leaves.texture = leafTexture;
leaves.velocity = new Vector3(-2, -2, 0);
leaves.velocityFactor = new Vector3(2, 2, 2);
leaves.fadeIn = true;
leaves.fadeOut = true;
leaves.start();

// debug
// const gui = new dat.GUI()

// const cameraFolder = gui.addFolder('camera');
// cameraFolder.add(camera.position, 'x', -1, 1)
// cameraFolder.add(camera.position, 'y', -1, 1)
// cameraFolder.add(camera.position, 'z', 0, 100)

// console.log('over')
